<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<meta http-equiv="keywords" content="" />
		<meta http-equiv="description" content="" />
		<title>工房受注管理</title>

		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<script src="assets/scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		
		<script src="assets/scripts/ui/jquery-ui-1.7.2.custom.js" type="text/javascript"></script>
		<link type="text/css" href="./assets/styles/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<style type="text/css">
			.nobinput{
				border-width: 0px;
				font-family: inherit;
				padding: 3px 5px;
				text-align: center;
			}
			.nobinput2{
				border-width: 0px;
				font-family: inherit;
				padding: 3px 5px;
				/*text-align: center;*/
			}
		</style>
		<script type="text/javascript">
		
		$(function() {

			// メッセージのフェード
			$('.message').fadeIn("slow");

			// 戻るボタン押下
			$('#btn_back').click(function(){
				document.fm.mode.value = 'back';
				document.fm.submit();
			});
			
		});
		</script>	
		
		<script type="text/javascript">
		
			function deleteAction(id){
				if(confirm("削除してもよろしいでしょうか?")){
					window.location.href='make_price.php?consumer_id={{$consumer.consumer_id}}&price_no='+id+'&&mod=delete';
				}else{
					return false;
				}
			} 

			//コントロールお客様は状態に同意する
			function controlStatus(){
				document.getElementById("status").style.display = 'block';
				document.getElementById("status1").style.display = 'none';
			}
		</script>
		
		<script type="text/javascript">
			function deleteAction(){
				if(confirm("削除してもよろしいでしょうか?")){
					window.location.href='order_make_price.php?order_id={{$order.order_id}}&&mod=delete';
				}else{
					return false;
				}
			} 

			function controlPayment_term(){
				var payment_term = document.getElementById("payment_term");
				var payment1 = document.getElementById("payment1");
				var payment2 = document.getElementById("payment2");
				if(payment2.checked){
					payment_term.readOnly = false;
				}
				if(payment1.checked){
					payment_term.readOnly = true;
				}
			}
		</script>
		
		<!--タイムコントロール -->
		<script>
			$(document).ready(function(){ 
				$("#start_date").wrDate();  
				$("#end_date").wrDate();
				$("#start_date1").wrDate();  
				$("#end_date1").wrDate();
			});
	
			$.extend({ 
				wrDate : function(objs) { 
				objs.each(function(i) { 
					//jQueryオブジェクトをトラバース
					var inputObj = $(this); 
					inputObj.datepicker({
						changeMonth: true,
						changeYear: true,
						dateFormat: 'yy/mm/dd'
					}); //各jQueryオブジェクトにCalendarコントロール
				}); 
			}});
	
			$.fn.extend({ 
				wrDate : function() { 
				//wrDate jQueryプラグインの名前を定義します
				$.wrDate(this); //呼び出す前に、カスタムjQuery関数 
			}});
			
		</script>	
		
		<script language="javascript"> 
			  var rows = 10;
			  function addRow(){
				  rows++;
				  var html ="<tr>"+
				  	"<input type=\"hidden\" name=\"cost_price[]\" id=\"cost_price_"+rows+"\" value=\"0\" />"+
					"<input type=\"hidden\" name=\"shop_id[]\" id=\"shop_id_"+rows+"\" value=\"0\" />"+
					"<input type=\"hidden\" name=\"s_unit[]\" id=\"s_unit_"+rows+"\" value=\"\" />"+
					"	<td align=\"center\"><a href=\"javascript:void(openWin('order_shop_search.php?id="+rows+"', 600, 500));\">[マスタ選択]</a></td>"+
					"	<td><input type=\"text\" name=\"brand[]\" id=\"brand_"+rows+"\"   class=\"text\" readonly = \"readonly\" /></td>"+
					"	<td><input type=\"text\" name=\"shop_name[]\" id=\"shop_name_"+rows+"\"   class=\"text\" readonly = \"readonly\" /></td>"+
					"	<td><input type=\"text\" name=\"style[]\" id=\"style_"+rows+"\" size=\"10\"  class=\"text\" readonly = \"readonly\" /></td>"+
					"	<td align=\"center\"><input type=\"text\" name=\"refer_price[]\" id=\"refer_price_"+rows+"\"  class=\"text\" style=\"width: 25px;\" readonly = \"readonly\" /></td>"+
					"	<td align=\"center\"><input type=\"text\" name=\"num[]\" id=\"num_"+rows+"\" class=\"text\" style=\"width: 25px;\" onblur=\"priceChange("+rows+")\"  /></td>"+
					"	<td align=\"center\"><span id=\"money_"+rows+"\"></span></td>"+
					"</tr>";
				  $("#addrowid").before(html); 
			}

			  function openWin(u, w, h) { 
		            var l = (screen.width - w) / 2; 
		            var t = (screen.height - h) / 2; 
		            var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l; 
		            s += ', toolbar=no, scrollbars=yes, menubar=yes, location=no, resizable=yes'; 
		            open(u, 'oWin', s); 
		      } 
		      
		      var shopids = [];
		      {{ if $flag != 1 }}
		      {{ foreach from=$detail key=k item=v }}
		      	shopids.push({{$v.shop_id}});
		      {{/foreach}}
		      {{ /if }}
		      function validationRepeat(id){
		    	  for(var i=0;i<shopids.length;i++){
		    		  if(shopids[i]==id){
		    			  return false;
		    		  }
		    	  }
		    	  shopids.push(id);
		    	  return true;
		      }
		      
		      function priceChange(id){
		    	  	var refer_price =  (document.getElementById("refer_price_"+id).value);
					var num = (document.getElementById("num_"+id).value);
					var cost_price = (document.getElementById("cost_price_"+id).value);
					if(num==''){
						return ;
					}
					var pattern = /^\d+$/;
					if(!pattern.test(num)){
						alert("半角数字で入力して下さい");
						return ;
					}
					
					if(isNaN(refer_price) || isNaN(cost_price) || refer_price==''){
						return ;
					}
					
					refer_price = parseFloat(refer_price);
					num = parseFloat(num);
					cost_price = parseFloat(cost_price);
					document.getElementById("money_"+id).innerHTML=formatNumber(parseInt((refer_price)*(num)));
					
					compute();
					
		      }
		      
		      function compute(){
		    	  
		    	  var m1 = 0;
					for(var i=1;i<=rows;i++){
						if(document.getElementById("money_"+i).firstChild != null){
							var tempv=document.getElementById("money_"+i).firstChild.nodeValue;
							var value = tempv.replace(",","");
							m1 = m1 + parseFloat(value);
						}
						
					}
					
					m1 = m1.toFixed(2);
					var discount = document.getElementById("discount").value;
					var pattern = /^\d+[.]?\d*$/;
					if(isNaN(discount) || !pattern.test(discount)){
						alert("半角数字で入力して下さい");
						return ;
					}
					discount = parseFloat(discount);
					
					var m2 = m1 * discount;
					m2=m2.toFixed(2);
					var m3 = m1 - m2;
					m3 = m3.toFixed(2);
					
					var delivery = document.getElementById("delivery").value;
					delivery = parseFloat(delivery);
					
					var m4 = (parseFloat(m2)+delivery)*{{$tax}};
					m4 = m4.toFixed(0);
					var m5 = parseFloat(m2)+parseFloat(m4)+parseFloat(delivery);
					m5 = m5.toFixed(2);
					document.getElementById("delivery_v").innerHTML=formatNumber(parseInt(delivery));
					document.getElementById("m1").innerHTML=formatNumber(parseInt(m1));
					document.getElementById("m2").innerHTML=formatNumber(parseInt(m2));
					document.getElementById("m3").innerHTML=formatNumber(parseInt(m3));
					document.getElementById("m4").innerHTML=formatNumber(parseInt(m4));
					document.getElementById("m5").innerHTML=formatNumber(parseInt(m5));
		      }
		      
		      function validation(){
		    	  var pattern = /^\d+[.]?\d*$/;
		    	  for(var i=1;i<=rows;i++){
						if(document.getElementById("shop_id_"+i).value > 0){
							var num = document.getElementById("num_"+i).value;
							if(isNaN(num) || !pattern.test(num)){
								alert("半角数字で入力して下さい");
								return false;
							}
							
						}
						
					}
		    	  
		    	  var discount = document.getElementById("discount").value;
					if(isNaN(discount) || !pattern.test(discount)){
						alert("半角数字で入力して下さい");
						return ;
					}
		    	  return true;
		      }
		      
		      function formatNumber(str) {
		    	  	str=str+"";
				    if(str.length <= 3){  
				        return str;  
				    } else {  
				        return formatNumber(str.substr(0,str.length-3))+','+str.substr(str.length-3);  
				    }  
				}
		</script> 
			
	</head>
	
	<body >
{{ php }} include( MENU_FILE ); {{ /php }}
		<div id="header" class="clearfix"><div class="wrapper">
			<h1><a href="./">コントロールパネル</a></h1>
			<form id="form_logout" action="logout.php" method="post"><p>{{ $login.staff_name }} <input type="submit" id="button_logout" value="ログアウト" /></p></form>
		</div></div>

		<div id="container">
		<div class="wrapper">
			<h2>工房受注管理</h2>
			<ul class="submenu clearfix">
				<li><a href="order_search.php">受注検索</a></li>								
				<li><a href="order.php">受注登録</a></li>
				<li><a href="order_shop.php">商品マスタ</a></li>
			</ul>
			
			<h3>見積書作成</h3>
			{{ if $phase == 'complete' }}
			<p class="message">作成完了しました</p>
			<ul>
				<li>&gt;&gt; <a href="orderInfo.php?order_id={{$order_id}}">一覧へ戻る</a></li>
			</ul>
			{{ elseif $phase == 'completeupdate' }}
			<p class="message">更新が完了しました</p>
			<ul>
				<li>&gt;&gt; <a href="orderInfo.php?order_id={{$order_id}}">一覧へ戻る</a></li>
			</ul>
			{{ else }}
			<h4>見積書一覧</h4>
			<ul>			
				<li>＞ <a href="orderInfo.php?order_id={{$order.order_id}}">戻る</a></li>
			</ul>
			
			<p class="message">見積書作成</p>
			
			
			<div id="mydiv3" style="width: 90%;border: 1px solid #ccc;">
			
			<form action="order_make_price.php" method="post" onsubmit="return validation() ">
			{{ if $flag == 1 }}<input type="hidden" name="mod" value="input" />{{else}}<input type="hidden" name="mod" value="update" />{{ /if }}
			<input type="hidden" name="order_id" value="{{$order.order_id}}" />
			<input type="hidden" name="tax" value="{{$tax}}" />
			<input type="hidden" name="category" value="{{$order.category}}" />
					<div style="width: 98%;margin-left:7px;">
						<div style="float: left;"><span style="font-size: 20px;">見積書作成</span></div>
						
					</div>
					<div style="clear: both;"></div>
					<table  class="formTable" style="width: 98%;margin-left:7px;">
						<thead>
							<tr>
								<th>受注日</th>
								<td>{{$order.o_date}}</td>
							</tr>
							
							<tr>
								<th>サービス名</th>
								<td>
								{{ if $order.category == 1 }}プリント工房PRO{{ /if }}
								{{ if $order.category == 2 }}プリント工房LITE{{ /if }}
								{{ if $order.category == 3 }}名刺工房{{ /if }}
								{{ if $order.category == 4 }}アルバム工房{{ /if }}
								</td>
							</tr>
							<tr>
								<th>氏名</th>
								<td>{{ $order.name }}</td>
							</tr>
							<tr>
								<th>住所</th>
								<td>{{ $order.address }}</td>
							</tr>
							<tr>
								<th>メールアドレス</th>
								<td>{{ $order.email }}</td>
							</tr>
							<tr>
								<th>納品日</th>
								<td>{{ $order.delivery_date }}</td>
							</tr>
						</thead>
					
					</table>
					
					
					<table class="formTable" style="width: 98%;margin-left:7px;">
	
							<tr align="center">
								<th>マスタ選択</th>
								<th>ブランド名</th>
								<th>商品名</th>
								<th>サイズ</th>
								<th>単価</th>
								<th>数量</th>
								<th>金額</th>			
							</tr>
							
							{{ if $flag == 1 }}
							{{section name=foo start=1 loop=11 step=1 }}
							<input type="hidden" name="cost_price[]" id="cost_price_{{$smarty.section.foo.index}}" value="0" />
							<input type="hidden" name="shop_id[]" id="shop_id_{{$smarty.section.foo.index}}" value="0" />
							<input type="hidden" name="s_unit[]" id="s_unit_{{$smarty.section.foo.index}}" value="" />
							
							<tr>
								<td align="center"><a href="javascript:void(openWin('order_shop_search.php?id={{$smarty.section.foo.index}}', 600, 500));">[マスタ選択]</a></td>
								<td><input type="text" name="brand[]" id="brand_{{$smarty.section.foo.index}}"   class="nobinput2" readonly = "readonly" /></td>
								<td><span id="shop_name_span_{{$smarty.section.foo.index}}"></span><input type="hidden" name="shop_name[]" id="shop_name_{{$smarty.section.foo.index}}"   class="nobinput2" readonly = "readonly" /></td>
								<td><input type="text" name="size[]" id="size_{{$smarty.section.foo.index}}" size="10"  class="nobinput" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="refer_price[]" id="refer_price_{{$smarty.section.foo.index}}"  class="nobinput" style="width: 55px;" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="num[]" id="num_{{$smarty.section.foo.index}}" class="text" style="width: 50px;" onblur="priceChange({{$smarty.section.foo.index}})"  /></td>
								<td align="center"><span id="money_{{$smarty.section.foo.index}}"></span></td>
							</tr>
							{{/section}}
							
							{{else}}
							
							{{ foreach from=$detail key=k item=v }}
							<input type="hidden" name="cost_price[]" id="cost_price_{{$k+1}}" value="{{$v.cost_price}}" />
							<input type="hidden" name="shop_id[]" id="shop_id_{{$k+1}}" value="{{$v.shop_id}}" />
							<input type="hidden" name="s_unit[]" id="s_unit_{{$k+1}}" value="{{$v.s_unit}}" />
							<input type="hidden" name="did[]"  value="{{$v.did}}" />
							<tr>
								<td align="center"><a href="javascript:void(openWin('order_shop_search.php?id={{$k+1}}', 600, 500));">[マスタ選択]</a></td>
								<td><input type="text" name="brand[]" id="brand_{{$k+1}}" value="{{$v.brand}}"   class="nobinput2" readonly = "readonly" /></td>
								<td><span id="shop_name_span_{{$k+1}}">{{$v.shop_name}}</span><input type="hidden" name="shop_name[]" id="shop_name_{{$k+1}}" value="{{$v.shop_name}}"  class="nobinput2" readonly = "readonly" /></td>
								<td><input type="text" name="size[]" id="size_{{$k+1}}" size="10" value="{{$v.style}}" class="nobinput" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="refer_price[]" id="refer_price_{{$k+1}}" value="{{$v.refer_price}}"  class="nobinput" style="width: 55px;" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="num[]" id="num_{{$k+1}}" class="text" value="{{$v.quantity}}" style="width: 50px;" onblur="priceChange({{$k+1}})"  /></td>
								<td align="center"><span id="money_{{$k+1}}">{{$v.money}}</span></td>						
							</tr>
							{{ /foreach }}
							{{section name=foo start=$num loop=11 step=1 }}
							<input type="hidden" name="cost_price[]" id="cost_price_{{$smarty.section.foo.index}}" value="0" />
							<input type="hidden" name="shop_id[]" id="shop_id_{{$smarty.section.foo.index}}" value="0" />
							<input type="hidden" name="s_unit[]" id="s_unit_{{$smarty.section.foo.index}}" value="" />
							<input type="hidden" name="did[]"  value="0" />
							<tr>
								<td align="center"><a href="javascript:void(openWin('order_shop_search.php?id={{$smarty.section.foo.index}}', 600, 500));">[マスタ選択]</a></td>
								<td><input type="text" name="brand[]" id="brand_{{$smarty.section.foo.index}}"   class="nobinput2" readonly = "readonly" /></td>
								<td><span id="shop_name_span_{{$smarty.section.foo.index}}"></span><input type="text" name="shop_name[]" id="shop_name_{{$smarty.section.foo.index}}"   class="nobinput2" readonly = "readonly"/></td>
								<td><input type="text" name="size[]" id="size_{{$smarty.section.foo.index}}" size="10"  class="nobinput" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="refer_price[]" id="refer_price_{{$smarty.section.foo.index}}"  class="nobinput" style="width: 55px;" readonly = "readonly" /></td>
								<td align="center"><input type="text" name="num[]" id="num_{{$smarty.section.foo.index}}" class="text" style="width: 50px;" onblur="priceChange({{$smarty.section.foo.index}})"  /></td>
								<td align="center"><span id="money_{{$smarty.section.foo.index}}"></span></td>						
							</tr>
							{{/section}}
							{{ /if }}
							<!-- 
							<tr id="addrowid">
								<td align="center"><a href="javascript:addRow();">[行を追加しま]</a></td>
								<td colspan="6"></td>
							</tr>
							 -->
		
					</table>
					
					<div style="width: 98%;margin-left:7px;">
						<div id="mydiv5" style="float: right;display: block;text-align: right;">
							<div>小計：￥<span id="m1">0</span></div>
							<div>値引き（掛け率）：<input type="text" name="discount" id="discount" value="{{if $flag == 0}}{{$order.discount}}{{else}}1{{/if}}" size="5" onblur="compute()" />&nbsp;￥<span id="m2">0</span>&nbsp(▲￥<span id="m3">0</span>)</div>
							<div>送料：
							<select name="shipping" id="delivery" onchange="compute()">
							{{ foreach from=$delivery_menu key=k item=v }}
							<option value="{{$k}}" {{if $order.shipping == $k }} selected {{/if}} >{{$v}}</option>
							{{ /foreach }}
							</select>&nbsp;￥<span id="delivery_v">0</span></div>
							<div>消費税：￥<span id="m4">0</span></div>
							<div>合計：￥<span id="m5">0</span></div>
						</div>					 
						<div style="clear: both;"></div>
					</div>
					
					<div style="margin-top: 20px;">
							<div style="margin-left: 25px;">&nbsp;備考&diams;&nbsp;
							<textarea style="width: 580px;height: 40px" name="quote_remark">{{$order.quote_remark}}</textarea>
							</div>
							<div style="margin-top: 10px;">&nbsp;特価理由&diams;&nbsp;
							<textarea style="width: 580px;height: 40px" name="quote_special">{{$order.quote_special}}</textarea>
							</div>							
					</div>
				  
					<br/>
						
					<div style="width: 98%;text-align: center;margin-left:7px;">
						<p class="button">
							{{ if $flag == 0 }}
							<button type="button" class="submit" onclick="deleteAction()" ><span>削除</span></button>
							<button type="button" class="submit" onclick="openWin('order_price_book.php?order_id={{$order.order_id}}',800,800)" ><span>単価稟議書印刷</span></button>
							<button type="button" class="submit" onclick="openWin('order_book.php?order_id={{$order.order_id}}',800,800)" ><span>見積書印刷</span></button>
							<button type="button" class="submit" onclick="window.location.href='order_make_price_csv.php?order_id={{$order.order_id}}'" ><span>CSV出力</span></button>
							{{ /if }}
							<button type="submit" class="submit" ><span>登録</span></button>
						</p>
					</div>
					</form>					
			</div>
			
			{{ if $flag == 0 }}
				<script>
				compute();
				</script>
			{{ /if }}
		{{ /if }}
		
		</div></div>
		<br/><br/>
		<address>Copyright (C) SHIFT Inc. / All rights reserved</address>
	</body>

</html>